package com.yyfax.pay.common.constants;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.yyfax.commons.lang.DateUtil;

/**
 * 富友存管常量管理
 * 
 * @author buyi
 * @date 2017-09-01 09:21:21
 * @since v2.0.0
 */
@Component
public class FuiouDepositConstant {

	@Resource
	private PayConstants payConstants;

	private String ebankChargeBackUrl = "/web/fuiou/charge/ebank/result/back/%s";

	private String ebankChargeNotifyUrl = "/api/fuiou/charge/ebank/result/back/%s";

	/** 交易文件上传，异步同通知地址，来自文件服务器 */
	private String fileTradeUploadNotifyUrl = "/api/fuiou/file/trade/upload/result/%s";

	/** 交易文件下载，异步同通知地址，来自文件服务器 */
	private String fileTradeDownloadNotifyUrl = "/api/fuiou/file/trade/download/result/%s";

	/** 交易文件回盘查询，异步通知地址，来自文件服务 */
	private String fileTradeQueryUrl = "/api/fuiou/file/trade/query/result/%s";

	/** 报备文件上传，异步同通知地址，来自文件服务器 */
	private String fileCheckUploadNotifyUrl = "/api/fuiou/file/check/upload/result/%s";

	/** 报备文件下载，异步同通知地址，来自文件服务器 */
	private String fileCheckDownloadNotifyUrl = "/api/fuiou/file/check/download/result/%s";

	/** 交易文件回盘查询，异步通知地址，来自文件服务 */
	private String fileCheckQueryUrl = "/api/fuiou/file/check/query/result/%s";

	/** 对账文件下载，异步同通知地址，来自文件服务器 */
	private String fileAccountDownloadNotifyUrl = "/api/fuiou/file/account/download/result/%s";

	/** 图片上传，异步通知地址，来自文件服务器 */
	private String fileImageUploadNotifyUrl = "/api/fuiou/file/image/upload/result/%s";

	/** 更换手机同步结果回调地址 */
	private String changePhonePageBackUrl = "/web/fuiou/account/change_phone/result/back/%s";

	/** 委托提现回调地址 */
	private String entrustWithdrawNotifyUrl = "/api/fuiou/entrust/withdraw/result/notify";

	/** 委托充值回调地址 */
	private String entrustChargeNotifyUrl = "/api/fuiou/entrust/charge/result/notify";

	/** 转账充值同步结果，异步通知地址 */
	private String transferChargeBackNotifyUrl = "/api/fuiou/charge/transfer/result/back/%s";

	/** 交易查询时间上下波动天 */
	@Value(value = "${pay.config.trade_query_day}")
	public int queryDay;
	
	@Value(value = "${pay.fuioudeposit.query_protocol_start_date:20180601}")
	public String queryProtocolStartDate;
	
	@Value(value = "${pay.fuioudeposit.query_protocol_end_date:20180801}")
	public String queryProtocolEndDate;

	/** 开户、换卡用的地区代码，默认北京 */
	public static final String CITY_CODE_BEIJING = "1000";

	public PayConstants getPayConstants() {
		return payConstants;
	}

	public void setPayConstants(PayConstants payConstants) {
		this.payConstants = payConstants;
	}

	private String getEbankChargeBackUrl() {
		return payConstants.getDomain().concat(ebankChargeBackUrl);
	}

	private String getEbankChargeNotifyUrl() {
		return payConstants.getDomain().concat(ebankChargeNotifyUrl);
	}

	private String getFileTradeUploadNotifyUrl() {
		return payConstants.getInnerDomain().concat(fileTradeUploadNotifyUrl);
	}

	private String getFileTradeDownloadNotifyUrl() {
		return payConstants.getInnerDomain().concat(fileTradeDownloadNotifyUrl);
	}

	public String getFileImageUploadNotifyUrl() {
		return payConstants.getInnerDomain().concat(fileImageUploadNotifyUrl);
	}

	public void setFileImageUploadNotifyUrl(String fileImageUploadNotifyUrl) {
		this.fileImageUploadNotifyUrl = fileImageUploadNotifyUrl;
	}

	private String getChangePhonePageBackUrl() {
		return payConstants.getDomain().concat(changePhonePageBackUrl);
	}

	private String getFileCheckUploadNotifyUrl() {
		return payConstants.getInnerDomain().concat(fileCheckUploadNotifyUrl);
	}

	private String getFileCheckDownloadNotifyUrl() {
		return payConstants.getInnerDomain().concat(fileCheckDownloadNotifyUrl);
	}

	private String getFileTradeQueryUrl() {
		return payConstants.getInnerDomain().concat(fileTradeQueryUrl);
	}

	private String getFileCheckQueryUrl() {
		return payConstants.getInnerDomain().concat(fileCheckQueryUrl);
	}

	private String getFileAccountDownloadNotifyUrl() {
		return payConstants.getInnerDomain().concat(fileAccountDownloadNotifyUrl);
	}

	public String getTransferChargeBackNotifyUrl() {
		return payConstants.getDomain().concat(transferChargeBackNotifyUrl);
	}
	
	public String getQueryProtocolStartDate() {
		return queryProtocolStartDate;
	}

	public void setQueryProtocolStartDate(String queryProtocolStartDate) {
		this.queryProtocolStartDate = queryProtocolStartDate;
	}

	public String getQueryProtocolEndDate() {
		return queryProtocolEndDate;
	}

	public void setQueryProtocolEndDate(String queryProtocolEndDate) {
		this.queryProtocolEndDate = queryProtocolEndDate;
	}

	/**
	 * 获取网银同步通知地址
	 * 
	 * @author buyi
	 * @date 2017-09-01 09:49:06
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getEbankChargeBackUrl(String merchantCode) {
		return String.format(getEbankChargeBackUrl(), merchantCode);
	}

	/**
	 * 获取网银异步通知地址
	 * 
	 * @author buyi
	 * @date 2017-09-01 09:50:57
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getEbankChargeNotifyUrl(String merchantCode) {
		return String.format(getEbankChargeNotifyUrl(), merchantCode);
	}

	/**
	 * 获取上传文件异步通知地址
	 * 
	 * @author buyi
	 * @date 2017-09-07 15:06:23
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getFileTradeUploadNotifyUrl(String merchantCode) {
		return String.format(getFileTradeUploadNotifyUrl(), merchantCode);
	}

	/**
	 * 获取下载文件异步通知地址
	 * 
	 * @author buyi
	 * @date 2017-09-07 15:06:41
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getFileTradeDownloadNotifyUrl(String merchantCode) {
		return String.format(getFileTradeDownloadNotifyUrl(), merchantCode);
	}

	/**
	 * 获取报备上传文件结果异步通知路径
	 * 
	 * @author buyi
	 * @date 2017-09-22 14:35:34
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getFileCheckUploadNotifyUrl(String merchantCode) {
		return String.format(getFileCheckUploadNotifyUrl(), merchantCode);
	}

	/**
	 * 获取报备下载文件结果异步通知路径
	 * 
	 * @author buyi
	 * @date 2017-09-22 14:35:51
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getFileCheckDownloadNotifyUrl(String merchantCode) {
		return String.format(getFileCheckDownloadNotifyUrl(), merchantCode);
	}

	/**
	 * 获取图片上传结果异步通知路径
	 * 
	 * @author buyi
	 * @date 2018-03-29 16:57:22
	 * @since v2.1.3
	 * @param merchantCode
	 * @return
	 */
	public String getFileImageUploadNotifyUrl(String merchantCode) {
		return String.format(getFileImageUploadNotifyUrl(), merchantCode);
	}

	/**
	 * 获取更换手机同步页面回调地址
	 * 
	 * @author buyi
	 * @date 2017-09-09 11:47:45
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getChangePhonePageBackUrl(String merchantCode) {
		return String.format(getChangePhonePageBackUrl(), merchantCode);
	}

	/**
	 * 获取委托提现回调地址
	 *
	 * @author yejca
	 * @date 2017-09-09 11:47:45
	 * @since v2.0.0
	 * @return
	 */
	public String getEntrustWithdrawNotifyUrl() {
		return payConstants.getDomain().concat(entrustWithdrawNotifyUrl);
	}

	/**
	 * 获取委托充值回调地址
	 *
	 * @author yejca
	 * @date 2017-09-21
	 * @since v2.0.0
	 * @return
	 */
	public String getEntrustChargeNotifyUrl() {
		return payConstants.getDomain().concat(entrustChargeNotifyUrl);
	}

	/**
	 * 交易查询的开始日期 yyyyMMdd
	 * 
	 * @author heizq
	 * @date 2017-09-28 18:59:47
	 * @since v1.0.0
	 * @return
	 */
	public Date getTradeQueryStartDay(Date indexDate) {
		return DateUtil.addDay(indexDate, -queryDay);
	}

	/**
	 * 交易查询的结束日期 yyyyMMdd
	 * 
	 * @author heizq
	 * @date 2017-09-28 18:59:47
	 * @since v1.0.0
	 * @return
	 */
	public Date getTradeQueryEndDay(Date indexDate) {
		return DateUtil.addDay(indexDate, queryDay);
	}

	/**
	 * 获取交易回盘文件异步通知地址
	 * 
	 * @author buyi
	 * @date 2017-10-09 16:17:30
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getFileTradeQueryUrl(String merchantCode) {
		return String.format(getFileTradeQueryUrl(), merchantCode);
	}

	/**
	 * 获取报备回盘文件异步通知地址
	 * 
	 * @author buyi
	 * @date 2017-10-09 16:17:48
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getFileCheckQueryUrl(String merchantCode) {
		return String.format(getFileCheckQueryUrl(), merchantCode);
	}

	/**
	 * 获取对账下载文件异步通知地址
	 * 
	 * @author buyi
	 * @date 2017-10-10 14:40:55
	 * @since v2.0.0
	 * @param merchantCode
	 * @return
	 */
	public String getFileAccountDownloadNotifyUrl(String merchantCode) {
		return String.format(getFileAccountDownloadNotifyUrl(), merchantCode);
	}

	/**
	 * 获取转账充值同步结果异步通知地址
	 * 
	 * @author buyi
	 * @date 2018-03-28 11:00:16
	 * @since v2.0.4
	 * @param merchantCode
	 * @return
	 */
	public String getTransferChargeBackNotifyUrl(String merchantCode) {
		return String.format(getTransferChargeBackNotifyUrl(), merchantCode);
	}
}
